package ch9;

import java.util.Scanner;

public class EmailClass {
	
	//https://www.cnblogs.com/ming-szu/p/8915374.html

	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		System.out.println("");
		String emaString = scanner.nextLine();
		
		//2.1
		if(emaString.indexOf("@")==-1 && emaString.indexOf(".")==-1) {
			System.out.println("邮箱地址不包含@和.");
		}else if(emaString.indexOf("@")!=emaString.lastIndexOf("@")
				|| emaString.indexOf(".")!=emaString.lastIndexOf(".")){
			System.out.println("包含了多了的@和.");
	
		}else if (emaString.indexOf("@") > emaString.indexOf(".")) {
			System.out.println(".在@的前面");
			
		}else if (!checkEmailContent(emaString)) {
			System.out.println("用户名有其他字符，只能包含字母和数字");
		}else {
			System.out.println("有效邮箱");
		}

	}
	
	private static boolean checkEmailContent(String email) {
		for(int i=0;i<email.length();i++) {
			char c = email.charAt(i);
			boolean flag = c>+'A' && c<='Z' || c>='a' && c<='z' || c=='@'|| c=='.';
			if(flag) {
				continue;
			}else {
				return false;
			}
		}
		
		return true;
	}

}
